package control
{
	import model.ModelLocator;
	import flash.events.Event;
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;
	
	import view.Markers;
	public class ShowAllShareMarkers
	{
		internal var theModel:ModelLocator = ModelLocator.getInstance();
		private var ShowAllShareMarkersRO:RemoteObject;
		public var mark:view.Markers;
		public function ShowAllShareMarkers(mark:view.Markers)
		{
			this.mark = mark;
			ShowAllShareMarkersRO = new RemoteObject();
			ShowAllShareMarkersRO.destination="ShowAllShareMarkers";
			ShowAllShareMarkersRO.doShowAllShareMarkers.addEventListener(ResultEvent.RESULT,ShowAllShareMarkersResultHandler);
			ShowAllShareMarkersRO.addEventListener(FaultEvent.FAULT, ShowAllShareMarkersFaultHandler);
		}
		
		public function doShowAllShareMarkers():void
		{
			ShowAllShareMarkersRO.doShowAllShareMarkers(theModel.user.user_id);
		}
		
		internal function ShowAllShareMarkersResultHandler(event:ResultEvent):void
		{
				//Alert.show("show shared markers Successfully.");
				theModel.allShowAllShareMarkers = event.result as ArrayCollection;
				//Alert.show(theModel.allShowAllShareMarkers[1]['username']);
				theModel.dispatchEvent(new Event(ModelLocator.SHOWALLSHAREMARKERS_OK));
				//Alert.show("dispatchEvent");
				theModel.dispatchEvent(new Event(ModelLocator.SHOWALLSHAREMARKERS_OK));
		}
		
		internal function ShowAllShareMarkersFaultHandler(event:ResultEvent):void
		{
			Alert.show("error occur when show the shared markers");
		}
	}
}